import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, SetMetadata } from "@nestjs/common";
import { PermissionService } from "./permission.service";
import { CreatePermissionDto } from "./dto/create-permission.dto";
import { UpdatePermissionDto } from "./dto/update-permission.dto";
import { AuthGuard } from "src/auth/auth.guard";
import { RolesGuard } from "src/auth/roles.guard";

@Controller("/mg/permission")
export class PermissionController {
    constructor(private readonly permissionService: PermissionService) {}

    @UseGuards(AuthGuard, RolesGuard) 
    @SetMetadata("roles", ["超级管理员"])
    @Post()
    create(@Body() createPermissionDto: CreatePermissionDto) {
        console.log("createPermissionDto", createPermissionDto);
        return this.permissionService.create(createPermissionDto);
    }

    @Get()
    findAll() {
        return this.permissionService.findAll();
    }

    @Get(":id")
    findOne(@Param("id") id: string) {
        return this.permissionService.findOne(id);
    }

    @UseGuards(AuthGuard, RolesGuard) 
    @SetMetadata("roles", ["超级管理员"])
    @Patch(":id")
    update(@Param("id") id: string, @Body() updatePermissionDto: UpdatePermissionDto) {
        return this.permissionService.update(id, updatePermissionDto);
    }

    @UseGuards(AuthGuard, RolesGuard) 
    @SetMetadata("roles", ["超级管理员"])
    @Delete(":id")
    remove(@Param("id") id: string) {
        return this.permissionService.remove(id);
    }
}
